<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>可选参数</title>
</head>
<body>
    <script>
        const user = {
            employee: {
                name: "Kapil"
            }
        };
        // user.employee?.name;
        console.log('%c   user.employee?.name: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', user.employee?.name);
        // Output: "Kapil"
        // user.employ?.name;
        console.log('%c   user.employ?.name: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', user.employ?.name);
        // Output: undefined
        // user.employ.name
        console.log('%c   user.employ.name: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', user.employ.name);
        // 输出: VM21616:1 Uncaught TypeError: Cannot read property 'name' of undefined


        const obj = {
            hh:"xxx"
        }
        let res = obj?.data?.list
        //    todo:等价
        // let res = obj?.data?.list
        //    todo： <=等价=>

        //todo: 双问号后面接的就是默认值。
        let res1 = obj && obj.data && obj.data.list
        var obj ={}
        console.log(obj?.a?.b ?? 233 ) //233
        var obj={a:{b:1}}
        console.log(obj?.a?.b??233) //1
    </script>
</body>
</html>